package com.njbdqn.qiy_book.bookcontroller;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.njbdqn.commons.services.OutputService;

import com.njbdqn.qiy_book.service.BooksService;
import com.njbdqn.qiy_book.vo.BooknameVO;
import com.njbdqn.qiy_book.vo.SlideVO;
import com.njbdqn.qiy_book.vo.TypeBookVO;
import com.njbdqn.qiy_book.vo.TypenameVO;

/**
 * Servlet implementation class SameTypeController
 */
public class SameTypeController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String bookname = request.getParameter("bookname");
		System.out.println(bookname);

		BooksService bss = new BooksService();
		List<TypeBookVO> tbvo = new ArrayList<TypeBookVO>();

		List<BooknameVO> bnv = bss.BookSameType(bookname);
		List<TypenameVO> tnv = bss.TypeSameType(bookname);
		SlideVO sv = bss.SameType(bookname).get(0);

		TypeBookVO tbv = new TypeBookVO();
		try {
			BeanUtils.copyProperties(tbv, sv);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tbv.setBook(bnv);
		tbv.setType(tnv);
		tbvo.add(tbv);

		OutputService.out(response, tbvo);

	}

}
